function currying(fn) {
  var slice = Array.prototype.slice;
  var _args = slice.call(arguments, 1);
  return function () {
    var _inargs = slice.call(arguments);
    return fn.apply(null, _args.concat(_inargs));
  };
}

// 例1
function square(i) {
  return i * i;
}
function dubble(i) {
  return (i *= 2);
}
function map(handler, list) {
  return list.map(handler);
}
// console.log(map(square, [1, 3, 5, 3, 2]));
// console.log(map(dubble, [1, 3, 5, 3, 2]));

var mapSQ = currying(map, square);
// console.log(mapSQ([1, 3, 5, 3, 2]));

var mapSQ2 = currying(map, dubble);
// console.log(mapSQ2([1, 3, 5, 3, 2]))

// bind

const arr = [];
function foo() {
  const _args = Array.prototype.slice.call(arguments);
  this.push(..._args)
  return this;
}
// console.log(foo.bind(arr, 1)(2));

Function.prototype.bind = function (context) {
  var _this = this,
    _args = Array.prototype.slice.call(arguments, 1);
  return function () {
    return _this.apply(
      context,
      _args.concat(Array.prototype.slice.call(arguments))
    );
  };
};
console.log(foo.bind(arr, 1)(2));
